package main

import (
	"fmt"
	"strconv"
	"unicode"
)

func main() {
	s := "a1b2c3"
	ch := s[1]
	fmt.Println(unicode.IsDigit(rune(ch)))  //true
	fmt.Println(unicode.IsLetter(rune(ch))) //false
	fmt.Println(unicode.IsNumber(rune(ch))) //true

	s2 := "你好呀hhh"
	fmt.Println(len(s2))         //12 (一个中文字符占用三个长度)
	fmt.Println(s2[0])           //228
	fmt.Printf("%s \n", s2[0:3]) //你

	runes := []rune(s2)
	fmt.Println(runes, len(runes)) //[20320 22909 21568 104 104 104]	6
	fmt.Println(runes[0] == '你')   //true

	// 字符转数字，字符转字符串，字符转ascii码
	c := '2'
	num := c - '0'
	fmt.Println(num)       //2
	fmt.Println(int(c))    //50
	fmt.Println(string(c)) //2

	// 字符串转整数
	str := "12"
	fmt.Println(strconv.Atoi(str)) //12 nil
	num = 15
	fmt.Println(string(num))            //没有输出
	fmt.Println(strconv.Itoa(int(num))) //15

}
